#ifndef YOOHOO_XMPPCORE_STANZAERROR_H
#define YOOHOO_XMPPCORE_STANZAERROR_H

#include "xmppcore/abstracterror.h"
#include "xmppcore/protocolkey.h"
#include "xmppcore/stanza.h"

namespace yoohoo_xmppcore {

class YOOHOO_XMPPCORE_EXPORT StanzaError : public Stanza, public Error {
public:
	static const ProtocolKey PROTOCOL_KEY;
	static const ProtocolKey ERROR_DETAIL_PROTOCOL_KEY;

	enum StanzaErrorType {
		StanzaErrorTypeCancel,
		StanzaErrorTypeContinue,
		StanzaErrorTypeModify,
		StanzaErrorTypeAuth,
		StanzaErrorTypeWait
	};

	StanzaError(StanzaErrorType stanzaErrorType = StanzaError::StanzaErrorTypeCancel, QString definedCondition = QString(),
		XmlLangText text = XmlLangText());
	~StanzaError();
	void setSenderXml(QString senderXml);
	QString senderXml();
	bool shouldCloseStream();
	void setApplicationSpecificCondition(XmppObject* applicationSpecificCondition);
	XmppObject* applicationSpecificCondition();
	void setDefinedCondition(QString definedCondition);
	QString definedCondition();
	void setText(XmlLangText text);
	XmlLangText text();
	void setStanzaKind(Stanza::StanzaKind stanzaKind);
	Stanza::StanzaKind stanzaKind() const;
	void setStanzaErrorType(StanzaError::StanzaErrorType stanzaErrorType);
	StanzaError::StanzaErrorType stanzaErrorType();
	void setAttanchSenderXml(bool attachSenderXml);
	bool attachSenderXml();
	QString type();
	XmppElement::ElementType elementType() const;
	Error::ErrorType errorType() const;

private:
	Stanza::StanzaKind _stanzaKind;
	bool _attachSenderXml;
	QString _senderXml;
	StanzaError::StanzaErrorType _stanzaErrorType;
	AbstractError* _errorImpl;
	
class StanzaErrorImpl : public AbstractError {
public:
	StanzaErrorImpl(StanzaError* stanzaError);
	bool shouldCloseStream();
	XmppElement::ElementType elementType() const;
	Error::ErrorType errorType() const;

protected:
	QString definedConditionNamespace();
	void writeErrorHeader(XmlWriter* writer);
	void writeErrorFooter(XmlWriter* writer);

private:
	StanzaError* _stanzaError;
};

};

}

#endif
